//
//  TJTaskManagerListCell.m
//  BaoDian
//
//  Created by mac on 2024/8/3.
//

#import "TJTaskManagerListCell.h"
#import "TJUserPublishDataView.h"

@interface TJTaskManagerListCell()

@property (nonatomic, weak) UILabel *nameLabel;
@property (nonatomic, weak) TJUserPublishDataView *dataView;
@property (nonatomic, weak) UILabel *stateValueLabel;
@property (nonatomic, weak) UILabel *numberValueLabel;
@property (nonatomic, weak) UILabel *dateValueLabel;


@end

@implementation TJTaskManagerListCell

- (void)settingSubView {
    [super settingSubView];
    
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = UIColor.tj_backgroundColor;
    
    UIView *tj_contentView = [UIView addToView:self.contentView];
    tj_contentView.backgroundColor = UIColor.tj_1E1F23Color;
    tj_contentView.addCornerRadius(12);
    [tj_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.inset(16);
        make.top.offset(0);
    }];
    
    UIView *topView = [UIView addToView:tj_contentView];
    [topView addTapGesturesWithTarget:self action:@selector(tapTopView)];
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(0);
        make.top.offset(0);
        make.height.offset(48);
    }];
    
    UIImageView *iconImageView = [UIImageView addToView:topView];
    iconImageView.image = [UIImage imageNamed:@"groupIcon"];
    [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.offset(20);
        make.centerY.offset(0);
        make.left.offset(16);
    }];
    
    UILabel *nameLabel = [UILabel lableWithSuperView:topView font:UIFontMake(16) color:UIColor.whiteColor title:nil textAlignment:NSTextAlignmentCenter];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.left.equalTo(iconImageView.mas_right).offset(6);
    }];
    
    UIImageView *arrowImageView = [UIImageView addToView:topView];
    arrowImageView.image = [UIImage imageNamed:@"arrow_1"];
    [arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(16);
        make.centerY.offset(0);
        make.width.height.offset(16);
    }];
    
    UILabel *detailLabel = [UILabel lableWithSuperView:topView font:UIFontMake(12) color:UIColor.tj_8D9298Color title:@"查看详情" textAlignment:NSTextAlignmentLeft];
    [detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.offset(0);
        make.right.equalTo(arrowImageView.mas_left);
    }];

    UIView *lineView = [UIView addToView:topView];
    lineView.backgroundColor = UIColorMake(0x2A2B31);
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.inset(16);
        make.height.offset(1);
        make.bottom.offset(0);
    }];
    
    TJUserPublishDataView *dataView = [TJUserPublishDataView addToView:tj_contentView];
    dataView.backgroundColor = UIColorMake(0x2A2B31);
    dataView.addCornerRadius(8);
    [dataView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(lineView);
        make.height.offset(52);
        make.top.equalTo(topView.mas_bottom).offset(12);
    }];
    
    UILabel *stateLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"发布状态" textAlignment:NSTextAlignmentLeft];
    [stateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dataView.mas_bottom).offset(14);
        make.left.inset(16);
    }];
    
    UILabel *stateValueLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(12) color:UIColorMake(0xEF382D) title:nil textAlignment:NSTextAlignmentCenter];
    stateValueLabel.addCornerRadius(4);
    stateValueLabel.layer.borderWidth = 0.5;
    stateValueLabel.layer.borderColor = UIColorMake(0xEF382D).CGColor;
    [stateValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(stateLabel);
        make.right.inset(16);
        make.width.offset(44);
        make.height.offset(18);
    }];

    
    UILabel *dateLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"发布时间" textAlignment:NSTextAlignmentLeft];
    [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(stateLabel.mas_bottom).offset(10);
        make.left.equalTo(iconImageView);
    }];
    
    UILabel *dateValueLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:nil textAlignment:NSTextAlignmentLeft];
    [dateValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(dateLabel);
        make.right.equalTo(lineView);
    }];
    
    UILabel *numberLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:@"参与人数" textAlignment:NSTextAlignmentLeft];
    [numberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dateLabel.mas_bottom).offset(10);
        make.left.equalTo(iconImageView);
    }];
    
    UILabel *numberValueLabel = [UILabel lableWithSuperView:tj_contentView font:UIFontMake(14) color:UIColor.tj_8D9298Color title:nil textAlignment:NSTextAlignmentLeft];
    [numberValueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(numberLabel);
        make.right.equalTo(lineView);
    }];
    
    _stateValueLabel = stateValueLabel;
    _numberValueLabel = numberValueLabel;
    _dataView = dataView;
    _nameLabel = nameLabel;
    _dateValueLabel = dateValueLabel;
}


- (void)setModel:(TJTaskManageModel *)model {
    _model = model;
    
    _nameLabel.text = model.taskName;
    _dateValueLabel.text = model.createDate;
    
    _numberValueLabel.text = [NSString stringWithFormat:@"%@人", model.userNumber];
    _dataView.publishCountItem.textLabel.text = model.sendCount;
    _dataView.playerCountItem.textLabel.text = model.playCount;
    _dataView.likeCountItem.textLabel.text = model.diggCount;
    _dataView.commentCountItem.textLabel.text = model.commentCount;
    
    if (model.taskStatus.intValue == 3) {
        _stateValueLabel.layer.borderColor = UIColorMake(0x2978F0).CGColor;
        _stateValueLabel.textColor = UIColorMake(0x2978F0);
        _stateValueLabel.text = @"进行中";

    } else if (model.taskStatus.intValue == 5) {
        _stateValueLabel.layer.borderColor = UIColorMake(0xEF382D).CGColor;
        _stateValueLabel.textColor = UIColorMake(0xEF382D);
        _stateValueLabel.text = @"已结束";
    } else if (model.taskStatus.intValue == 4) {
        _stateValueLabel.layer.borderColor = UIColor.tj_8D9298Color.CGColor;
        _stateValueLabel.textColor = UIColor.tj_8D9298Color;
        _stateValueLabel.text = @"已终止";
    } else {
        _stateValueLabel.layer.borderColor = UIColor.tj_8D9298Color.CGColor;
        _stateValueLabel.textColor = UIColor.tj_8D9298Color;
        _stateValueLabel.text = @"未启动";
    }
}
- (void)tapTopView {
    if (_tapTopViewBlock) {
        _tapTopViewBlock();
    }
}
 

@end
